
package com.voicecheck.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aris.voicechecking.R;
import com.voicecheck.adapter.DayLessonAdapter.DayLessonHolder;
import com.voicecheck.model.DayLesson;

public class DayLessonAdapter extends RecyclerView.Adapter<DayLessonHolder> {

    protected List<DayLesson> listData;

    protected Context ct;

    static OnItemClickListener mItemClickListener;

    public DayLessonAdapter(List<DayLesson> ldata) {
        listData = ldata;
    }

    @Override
    public int getItemCount() {

        return listData.size();

    }

    @Override
    public void onBindViewHolder(DayLessonHolder arg0, int arg1) {
        DayLesson less = listData.get(arg1);
        arg0.tittle.setText("Day" + (arg1 + 1) + ": " + less.getTitle());
        arg0.tittle.setTextColor(Color.BLACK);

        arg0.question_number.setText(less.getNumber_question_available() + "/6 "
                + ct.getString(R.string.question));

        arg0.question_number.setTextColor(Color.BLACK);

    }

    @Override
    public DayLessonHolder onCreateViewHolder(ViewGroup arg0, int arg1) {

        View contentView = LayoutInflater.from(arg0.getContext()).inflate(R.layout.item_lesson_day,
                arg0, false);
        ct = arg0.getContext();

        return new DayLessonHolder(contentView);

    }

    public static class DayLessonHolder extends RecyclerView.ViewHolder implements
    View.OnClickListener {

        TextView tittle;

        TextView question_number;

        public DayLessonHolder(View itemView) {
            super(itemView);

            tittle = (TextView)itemView.findViewById(R.id.lesson_title);
            question_number = (TextView)itemView.findViewById(R.id.question_number);
            itemView.setOnClickListener(this);

        }

        @Override
        public void onClick(View v) {

            if (DayLessonAdapter.mItemClickListener != null) {
                DayLessonAdapter.mItemClickListener.onItemClick(v, getPosition());
            }

        }

    }

    public interface OnItemClickListener {
        public void onItemClick(View view, int position);
    }

    public void SetOnItemClickListener(final OnItemClickListener mItemClickListener) {
        DayLessonAdapter.mItemClickListener = mItemClickListener;
    }

}
